
package com.example.constellation.partnerfrag;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.constellation.R;
import com.example.constellation.utils.AssetsUtils;
import com.example.constellation.utils.LoadDataAsyncTask;
import com.example.constellation.utils.URLContent;
import com.google.gson.Gson;

import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class PartnerAnalysisActivity extends AppCompatActivity implements LoadDataAsyncTask.OnGetNetDataListener, View.OnClickListener {
    TextView mantv,womantv,pdtv,vstv, pftv,bztv,jxtv,zytv,titletv;
    CircleImageView manIv,womanIv;
    ImageView backIv;
    private String man_name;
    private String woman_name;
    private String man_logoname;
    private String woman_logoname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_partner_analysis);
//        初始化操作
                initview();
                //接收上一个页面传递的数值
        getListData();


        String partnerUrl = URLContent.getPartnerUrl(man_name, woman_name);

        System.out.println("--------------"+partnerUrl);
        //加载网络数据
        //1.创造自定义的异步任务对象
        LoadDataAsyncTask loadDataAsyncTask = new LoadDataAsyncTask(this, this, true);
        loadDataAsyncTask.execute(partnerUrl);


    }
    @Override
    public void onSuccess(String json) {
        //json数据解析
        if (!TextUtils.isEmpty(json)) {
            PartnerAnalysisBean analysisBean=new Gson().fromJson(json,PartnerAnalysisBean.class);
            PartnerAnalysisBean.ResultBean result = analysisBean.getResult();

            pftv.setText("配对评分 : "+result.getZhishu()+"   "+result.getJieguo());
            bztv.setText("星座比重 : "+result.getBizhong());
            jxtv.setText("解析：\n\n"+result.getLianai());
            zytv.setText("注意事项：\n\n"+result.getZhuyi());



        }

    }

    private void getListData() {
        Intent intent=getIntent();
        man_name = intent.getStringExtra("man_name");
        woman_name = intent.getStringExtra("woman_name");
        man_logoname = intent.getStringExtra("man_logoname");
        woman_logoname = intent.getStringExtra("woman_logoname");
        //设置能够显示的控件信息
        Map<String, Bitmap> contentlogoImgMap= AssetsUtils.getContentlogoImgMap();
        Bitmap manBitmap=contentlogoImgMap.get(man_logoname);
        manIv.setImageBitmap(manBitmap);

        Bitmap womanBitmap=contentlogoImgMap.get(woman_logoname);
        womanIv.setImageBitmap(womanBitmap);

        mantv.setText(man_name);
        womantv.setText(woman_name);
        pdtv.setText("星座配对:"+man_name+"和"+woman_name+"配对");
        vstv.setText(man_name+"vs"+woman_name);



    }

    private void initview() {
        manIv=findViewById(R.id.partneranalysis_iv_man);
        womanIv=findViewById(R.id.partneranalysis_iv_woman);
        backIv=findViewById(R.id.title_iv_back);
        mantv=findViewById(R.id.partneranalysis_tv_man);
        womantv=findViewById(R.id.partneranalysis_tv_woman);

        pdtv=findViewById(R.id.parteranalysis_tv_pd);
        vstv=findViewById(R.id.parteranalysis_tv_vs);
        pftv=findViewById(R.id.parteranalysis_tv_pf);
        bztv=findViewById(R.id.parteranalysis_tv_bz);
        jxtv=findViewById(R.id.parteranalysis_tv_jx);
        zytv=findViewById(R.id.parteranalysis_tv_zy);
        titletv=findViewById(R.id.title_tv);

        backIv.setOnClickListener(this);
        titletv.setText("配对详情");
    }


    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.title_iv_back:
                finish();
                break;
        }

    }
}